package com.love.marriage.userCommissionWithdrawal.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSort;
import com.love.marriage.common.interfaces.avoid.AvoidRepeatableCommit;
import com.love.marriage.common.validator.Insert;
import com.love.marriage.common.validator.Update;
import com.love.marriage.common.vo.Result;
import com.love.marriage.common.vo.ResultBoolean;
import com.love.marriage.userCommissionWithdrawal.service.UserCommissionWithdrawalService;
import com.love.marriage.userCommissionWithdrawal.vo.ResultUserCommissionWithdrawalVo;
import com.love.marriage.userCommissionWithdrawal.vo.ResultUserCommissionWithdrawalVoPage;
import com.love.marriage.userCommissionWithdrawal.vo.UserCommissionWithdrawalVo;
import com.love.marriage.utils.StringUtils;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * description:  用户提现回佣金额历史表restApi
 * author:       mybatisPlus
 * createDate:   2025-01-29 19:43:00
 * version:      1.0.0
 */
@ApiSort(105)
@Tag(name = "用户提现回佣金额历史表相关接口", description = "用户提现回佣金额历史表相关接口")
@RestController
@RequiredArgsConstructor
@RequestMapping("/user-commission-withdrawal")
public class UserCommissionWithdrawalController {

    private final UserCommissionWithdrawalService userCommissionWithdrawalService;

    @ApiOperationSupport(order = 10, author = "mybatisPlus")
    @Operation(summary = "获取用户提现回佣金额历史表分页", description = "获取用户提现回佣金额历史表分页")
    @ApiResponse(responseCode = "200", description = "Success",
            content = @Content(mediaType = "application/json",
                    schema = @Schema(implementation = ResultUserCommissionWithdrawalVoPage.class
                    )))
    @PostMapping(value = "/page")
    @Parameters({
            @Parameter(name = "pageNum", description = "页码", required = false),
            @Parameter(name = "pageSize", description = "每页大小", required = false)
    })
    public Result<Page<UserCommissionWithdrawalVo>> getPage(@RequestParam(value = "pageNum", required = false) Long pageNum,
                                                            @RequestParam(value = "pageSize", required = false) Long pageSize,
                                                            @RequestBody(required = false) UserCommissionWithdrawalVo userCommissionWithdrawalVo) {
        return Result.success(userCommissionWithdrawalService.getPage(pageNum, pageSize, userCommissionWithdrawalVo));
    }

    @ApiOperationSupport(order = 15, author = "mybatisPlus")
    @Operation(summary = "获取用户提现回佣金额列表", description = "获取用户提现回佣金额列表")
    @ApiResponse(responseCode = "200", description = "Success",
            content = @Content(mediaType = "application/json",
                    schema = @Schema(implementation = ResultUserCommissionWithdrawalVoPage.class
                    )))
    @PostMapping(value = "/getList")
    public Result<List<UserCommissionWithdrawalVo>> getList(@RequestBody(required = false) UserCommissionWithdrawalVo userCommissionWithdrawalVo) {
        return Result.success(userCommissionWithdrawalService.getList(userCommissionWithdrawalVo));
    }

    @ApiOperationSupport(order = 20, author = "mybatisPlus")
    @Operation(summary = "获取用户提现回佣金额历史表详情", description = "获取用户提现回佣金额历史表详情")
    @ApiResponse(responseCode = "200", description = "Success",
            content = @Content(mediaType = "application/json",
                    schema = @Schema(implementation = ResultUserCommissionWithdrawalVo.class
                    )))
    @Parameters({
            @Parameter(name = "id", description = "id", required = true, schema = @Schema(implementation = Long.class, type = "Long", example = "1"))
    })
    @GetMapping
    public Result<UserCommissionWithdrawalVo> query(@RequestParam(value = "id") Long id) {
        return Result.success(userCommissionWithdrawalService.queryUserCommissionWithdrawal(id));
    }

    @AvoidRepeatableCommit
    @ApiOperationSupport(order = 30, author = "mybatisPlus")
    @Operation(summary = "新增用户提现回佣金额历史表", description = "新增用户提现回佣金额历史表",
            requestBody = @io.swagger.v3.oas.annotations.parameters.RequestBody(
                    description = "查询条件",
                    required = false,
                    content = @Content(schema = @Schema(implementation = UserCommissionWithdrawalVo.class))
            ))
    @ApiResponse(responseCode = "200", description = "Success",
            content = @Content(schema = @Schema(implementation = ResultUserCommissionWithdrawalVo.class)))
    @PostMapping
    public Result<UserCommissionWithdrawalVo> add(@Validated({Insert.class}) @RequestBody UserCommissionWithdrawalVo userCommissionWithdrawalVo) {
        return Result.success(userCommissionWithdrawalService.addUserCommissionWithdrawal(userCommissionWithdrawalVo));
    }

    @ApiOperationSupport(order = 40, author = "mybatisPlus")
    @Operation(summary = "修改用户提现回佣金额历史表", description = "修改用户提现回佣金额历史表",
            requestBody = @io.swagger.v3.oas.annotations.parameters.RequestBody(
                    description = "查询条件",
                    required = false,
                    content = @Content(schema = @Schema(implementation = UserCommissionWithdrawalVo.class))
            ))
    @ApiResponse(responseCode = "200", description = "Success",
            content = @Content(schema = @Schema(implementation = ResultUserCommissionWithdrawalVo.class)))
    @PutMapping
    public Result<UserCommissionWithdrawalVo> update(@Validated({Update.class}) @RequestBody UserCommissionWithdrawalVo userCommissionWithdrawalVo) {
        return Result.success(userCommissionWithdrawalService.updateUserCommissionWithdrawal(userCommissionWithdrawalVo));
    }

    @ApiOperationSupport(order = 50, author = "mybatisPlus")
    @Operation(summary = "刪除用户提现回佣金额历史表", description = "刪除用户提现回佣金额历史表")
    @Parameters({
            @Parameter(name = "ids", description = "ids,用，分割", required = true, schema = @Schema(implementation = String.class, type = "String", example = "1,2"))
    })
    @ApiResponse(responseCode = "200", description = "Success",
            content = @Content(schema = @Schema(implementation = ResultBoolean.class)))
    @DeleteMapping
    public Result<Boolean> delete(@RequestParam("ids") String ids) {
        return Result.success(userCommissionWithdrawalService.deleteUserCommissionWithdrawal(ids));
    }

    @AvoidRepeatableCommit
    @ApiOperationSupport(order = 70, author = "mybatisPlus")
    @Operation(summary = "审批提现", description = "审批提现")
    @ApiResponse(responseCode = "200", description = "Success",
            content = @Content(mediaType = "application/json",
                    schema = @Schema(implementation = ResultUserCommissionWithdrawalVo.class
                    )))
    @Parameters({
            @Parameter(name = "id", description = "用户提现id", required = true, schema = @Schema(implementation = Long.class, type = "Long", example = "1")),
            @Parameter(name = "status", description = "状态(COMPLETED:完成,CANCEL:取消)", schema = @Schema(implementation = String.class, type = "String", example = "1"))
    })
    @GetMapping(value = "submitUserCommissionWithdrawal")
    public Result<Boolean> submitUserCommissionWithdrawal(@RequestParam(value = "id") Long id,
                                                          @RequestParam(value = "status", required = false) String status) {
        if (StringUtils.isBlank(status)) {
            status = "COMPLETED";
        }
        return Result.success(userCommissionWithdrawalService.submitUserCommissionWithdrawal(id, status, null));
    }

    @ApiOperationSupport(order = 60, author = "mybatisPlus")
    @Operation(summary = "导出提现记录", description = "导出提现记录")
    @ApiResponse(responseCode = "200", description = "Success",
            content = @Content(mediaType = "application/json",
                    schema = @Schema(implementation = ResultBoolean.class
                    )))
    @PostMapping(value = "/export")
    public void export(@RequestBody(required = false) UserCommissionWithdrawalVo userCommissionWithdrawalVo, HttpServletResponse response) throws Exception {
        userCommissionWithdrawalService.export(userCommissionWithdrawalVo, response);
    }
}
